package dao;

import java.util.LinkedList;
import java.util.List;

import relations.Associate;
import relations.belongsTo;
import relations.handle;
import entities.Media_Company;
import entities.Product;
import entities.album;
import entities.order;
import entities.User;

public class HandleDAO {

	private static final HandleDAO instance = new HandleDAO();
	private List<handle> handleList;
	//private List<Media_Company>AssociateMediaComp;
	
	private HandleDAO(){
		handleList = new LinkedList<handle>();
	
		handle cus = null;
		
		//cus = Associate.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
		//cus = belongsTo.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
	}
	
	public static HandleDAO getInstance() {
		return instance;
	}

	public synchronized handle findHandle(String userID, Long product_id, String dateDay, String dateMonth, String dateYear, String description) {
		handle result = null;
	
		for (handle s : handleList){
			if (s.getUserID().equals(userID) && s.getProduct_id().equals(product_id) && s.getDateDay().equals(dateDay) && s.getDateMonth().equals(dateMonth) && s.getDateYear().equals(dateYear) && s.getDescription().equals(description)){
				result = s;
			
			}
		}
		
	
		return result;
	}

	public synchronized void addHandle(handle obj) throws RecordDuplicateException{
		if (findHandle(obj.getUserID(), obj.getProduct_id(), obj.getDateDay(), obj.getDateMonth(), obj.getDateYear(), obj.getDescription() ) != null){
			throw new RecordDuplicateException("Relation handle with User ID: " + obj.getUserID() + " and" + " Product ID: " + obj.getProduct_id() + " is already in the db.");
		}
		else {
			handleList.add(obj);
			
		}
	}

}
